package org.gwtmultipage.sample.server;

import javax.servlet.http.HttpSession;

import org.gwtmultipage.sample.client.InternationalizationService;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class InternationalizationServiceImpl extends RemoteServiceServlet implements InternationalizationService {
	private static final String INTERNATIONALIZATION_SESSION = "Language";
	private static final long serialVersionUID = 1L;

	@Override
	public String checkCurrentLanguage() {
		String language = getSiteLanguage();
		if(language != null) {
			return language;
		}
		return "null";
	}

	@Override
	public void currentLanguage(String language) {
		setSiteLanguage(language);		
	}
	
	private void setSiteLanguage(String language) {
		HttpSession session = getThreadLocalRequest().getSession();
	    session.setAttribute(INTERNATIONALIZATION_SESSION, language);
	}
	
	private String getSiteLanguage() {
		HttpSession session = getThreadLocalRequest().getSession();
	    return (String) session.getAttribute(INTERNATIONALIZATION_SESSION);
	}

}
